package com.unohacha.qqj.fzdr.main;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
import com.qpg.widget.common.ToastUtil;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.SupplyDemandTypeActivity;
import com.unohacha.qqj.fzdr.adapter.BaseRVAdapter;
import com.unohacha.qqj.fzdr.adapter.BaseViewHolder;
import com.unohacha.qqj.fzdr.bean.MyNewsModel;
import com.unohacha.qqj.fzdr.bean.homebean.HomeBannerBean;
import com.unohacha.qqj.fzdr.bean.homebean.HomeSpinCircleBean;
import com.unohacha.qqj.fzdr.fabu.ZhizaoActivity;
import com.unohacha.qqj.fzdr.imp.MyApplication;
import com.unohacha.qqj.fzdr.imp.MyCallBack;
import com.unohacha.qqj.fzdr.imp.UrlConfig;
import com.unohacha.qqj.fzdr.imp.XUtil;
import com.unohacha.qqj.fzdr.main.sends.SendOtherSupplyActivity;
import com.unohacha.qqj.fzdr.personal.bean.UserInfoBean;
import com.unohacha.qqj.fzdr.ui.activity.supply.BackRoadActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.EquipmentSupplyActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.ExcipientActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.FabricCateActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.LeaseOfHousesActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.RawMaterialActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.RecruitmentActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.TextileEquipmentActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.TextileStockActivity;
import com.unohacha.qqj.fzdr.util.GlideImageLoader;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.fzdr.util.ToastUtils;
import com.unohacha.qqj.fzdr.view.MyDialog;
import com.unohacha.qqj.mylibrary.base.BaseActivity;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 通用的供求
 */
public class CommonSDActivity extends BaseActivity implements OnRefreshLoadmoreListener {

    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.line_supply)
    TextView lineSupply;
    @BindView(R.id.supply_find_rl)
    RelativeLayout supplyFindRl;
    @BindView(R.id.common_title2)
    TextView commonTitle2;
    @BindView(R.id.line_need)
    TextView lineNeed;
    @BindView(R.id.need_find_rl)
    RelativeLayout needFindRl;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;
    @BindView(R.id.comment_banner)
    Banner commentBanner;
    @BindView(R.id.pt_line)
    ImageView ptLine;
    @BindView(R.id.car_list_recycler)
    RecyclerView carListRecycler;
    @BindView(R.id.mRefreshLayout)
    SmartRefreshLayout mRefreshLayout;
    @BindView(R.id.tab_ll)
    LinearLayout tabLl;
    @BindView(R.id.common_cancle)
    ImageView commonCancle;
    @BindView(R.id.edt_seach)
    EditText edtSeach;
    @BindView(R.id.common_right_search)
    TextView commonRightSearch;
    @BindView(R.id.search_ll)
    LinearLayout searchLl;
    @BindView(R.id.send_iv)
    ImageView send_iv;

    private int page = 1;
    private String supply_cate_id;//分类id
    private int typeid = 1;//1-供应 2-需求 
    private List<HomeSpinCircleBean.DataBeanX.DataBean> mDataList = new ArrayList<>();
    private List<String> mBannerList = new ArrayList<>();//banner的集合
    private List<HomeBannerBean.DataBean> mBannerAllList = new ArrayList<>();//banner所有数据的集合
    private BaseRVAdapter mBaseAdapter;
    private String title = "面料";
    private int homeType = 4;
    private String member_id;//首页最新推荐传过来的member_id值
    private String recommended_type;

    private int type_ps = 0;//个人用户认证(0-未认证，1-企业认证,2-已提交)
    private int type_ep = 0;//企业用户认证(0-未认证，1-企业认证,2-已提交)

    @Override
    protected int getLayoutId() {
        return R.layout.activity_common_sd;
    }

    @Override
    protected void initView() {
        super.initView();
        initRefresh();
        initIntentData();
        commonRightImage.setImageResource(R.drawable.ic_search_black);
        getMyNews();
        getSpinCircleData(supply_cate_id, typeid + "", "");
    }

    private void initIntentData() {//搜索框的

    }

    private void initRefresh() {
        mRefreshLayout.setOnRefreshLoadmoreListener(this);
        mRefreshLayout.setRefreshHeader(new ClassicsHeader(this));
        mRefreshLayout.setRefreshFooter(new ClassicsFooter(this));
        carListRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        carListRecycler.setHasFixedSize(true);
        carListRecycler.setNestedScrollingEnabled(false);
        if (null != getIntent()) {
            supply_cate_id = getIntent().getIntExtra("supply_cate_id", 0) + "";
            title = getIntent().getStringExtra("title");
            recommended_type = getIntent().getStringExtra("recommended_type");//推荐类型---1.供   2.求
//            title = getIntent().getStringExtra("type");
            
            if(recommended_type.equals("2")){//推荐类型--求
                typeid = 2;
                lineSupply.setVisibility(View.INVISIBLE);
                lineNeed.setVisibility(View.VISIBLE);
                commonTitle.setTextColor(getResources().getColor(R.color.text_black_666));
                commonTitle2.setTextColor(getResources().getColor(R.color.black));
                getSpinCircleData(supply_cate_id, typeid + "", "");
            }
            if (!TextUtils.isEmpty(getIntent().getStringExtra("member_id"))) {
                member_id = getIntent().getStringExtra("member_id");
            }
            if (title.contains("面料")) {
                commonTitle.setText(getResources().getString(R.string.title_mianliao_gy));
                commonTitle2.setText(getResources().getString(R.string.title_ml_need));
                homeType = 4;
            } else if (title.contains("织造")) {
                commonTitle.setText(getResources().getString(R.string.title_zz_gy));
                commonTitle2.setText(getResources().getString(R.string.title_zs_need));
                homeType = 5;
            } else if (title.contains("原料")) {
                commonTitle.setText(getResources().getString(R.string.title_yl_gy));
                commonTitle2.setText(getResources().getString(R.string.title_yl_need));
                homeType = 6;

            } else if (title.contains("招聘")) {
                commonTitle.setText(getResources().getString(R.string.title_zp_gy));
                commonTitle2.setText(getResources().getString(R.string.title_zp_need));
                homeType = 8;

            } else if (title.contains("求职")) {
                commonTitle.setText(getResources().getString(R.string.title_qz_gy));
                commonTitle2.setText(getResources().getString(R.string.title_qz_need));
                homeType = 29;
            }else if (title.contains("其他供求")){
                commonTitle.setText(getResources().getString(R.string.other_apply));
                commonTitle2.setText(getResources().getString(R.string.other_need));
                homeType = 14;
            }else if (title.contains("租赁")){
                commonTitle.setText(getResources().getString(R.string.rent_apply));
                commonTitle2.setText(getResources().getString(R.string.rent_need));
                homeType = 9;
            }else if (title.contains("其他供求")){
                commonTitle.setText(getResources().getString(R.string.other_apply));
                commonTitle2.setText(getResources().getString(R.string.other_need));
                homeType = 14;
            }else if (title.contains("库存")){
                commonTitle.setText(getResources().getString(R.string.store_apply));
                commonTitle2.setText(getResources().getString(R.string.store_need));
                homeType = 13;
            }else if (title.contains("纺织设备")){
                commonTitle.setText(getResources().getString(R.string.sheb_apply));
                commonTitle2.setText(getResources().getString(R.string.sheb_need));
                homeType = 10;
            }else if (title.contains("设备维修")){
                commonTitle.setText(getResources().getString(R.string.weix_apply));
                commonTitle2.setText(getResources().getString(R.string.weix_need));
                homeType = 12;
            }else if (title.contains("后道")){
                commonTitle.setText(getResources().getString(R.string.hd_apply));
                commonTitle2.setText(getResources().getString(R.string.hd_need));
                homeType = 11;
            }else if (title.contains("辅料")){
                commonTitle.setText(getResources().getString(R.string.fl_apply));
                commonTitle2.setText(getResources().getString(R.string.fl_need));
                homeType = 7;
            }
            getBannerData(homeType);
        }

    }

    @OnClick({R.id.common_back, R.id.need_find_rl, R.id.supply_find_rl,
            R.id.common_right_text, R.id.common_right_image, R.id.common_cancle,
            R.id.common_right_search, R.id.send_iv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                finish();
                break;
            case R.id.need_find_rl://需求
                typeid = 2;
                lineSupply.setVisibility(View.INVISIBLE);
                lineNeed.setVisibility(View.VISIBLE);
                commonTitle.setTextColor(getResources().getColor(R.color.text_black_666));
                commonTitle2.setTextColor(getResources().getColor(R.color.black));
                getSpinCircleData(supply_cate_id, typeid + "", "");
                break;
            case R.id.supply_find_rl://供应
                typeid = 1;
                lineSupply.setVisibility(View.VISIBLE);
                lineNeed.setVisibility(View.INVISIBLE);
                commonTitle.setTextColor(getResources().getColor(R.color.text_black_666));
                commonTitle2.setTextColor(getResources().getColor(R.color.black));
                commonTitle.setTextColor(getResources().getColor(R.color.black));
                commonTitle2.setTextColor(getResources().getColor(R.color.text_black_666));
                getSpinCircleData(supply_cate_id, typeid + "", "");
                break;
            case R.id.common_right_image://搜索
                searchLl.setVisibility(View.VISIBLE);
                edtSeach.setText("");
                tabLl.setVisibility(View.GONE);
                break;
            case R.id.common_cancle://取消
                searchLl.setVisibility(View.GONE);
                tabLl.setVisibility(View.VISIBLE);
                edtSeach.setText("");
                break;
            case R.id.common_right_search://搜索按钮
                if (!TextUtils.isEmpty(edtSeach.getText().toString().trim())) {
                    getSpinCircleData(supply_cate_id, typeid + "", edtSeach.getText().toString().trim());
                }
                break;
            case R.id.send_iv://发布
                Prefer.setType(typeid + "");
                if (homeType == 14){//其他供求
                   Intent intent = new Intent(this,SendOtherSupplyActivity.class);
                   intent.putExtra("id",supply_cate_id);
                   intent.putExtra("type",typeid);
                   startActivity(intent);
                }else if(homeType == 4){
                    Intent intent1=new Intent(CommonSDActivity.this, FabricCateActivity.class);
                    intent1.putExtra("main_id",supply_cate_id+"");
                    intent1.putExtra("type","2");
                    startActivity(intent1);
                }else if(homeType == 5){
                    Intent intent=new Intent(CommonSDActivity.this, ZhizaoActivity.class);
                    intent.putExtra("id",supply_cate_id+"");
                    intent.putExtra("type","1");
                    startActivity(intent);
                }else if(homeType == 6){
                    Intent intent5=new Intent(CommonSDActivity.this, RawMaterialActivity.class);
                    intent5.putExtra("id",supply_cate_id+"");
                    intent5.putExtra("type","1");
                    startActivity(intent5);
                }else if(homeType == 8){
                    Intent intent4=new Intent(CommonSDActivity.this, RecruitmentActivity.class);
                    intent4.putExtra("id",supply_cate_id+"");
                    intent4.putExtra("type","1");
                    startActivity(intent4);
                }else if(homeType == 12){
                    if (type_ps != 1) {
                        final MyDialog myDialog = new MyDialog(this);
                        myDialog.bottomClickListener(new MyDialog.MyBottomClickListener() {
                            @Override
                            public void bottomClick() {
                                myDialog.dismiss();
                            }
                        });
                        return;
                    }
                    Prefer.setType(typeid + "");
                    Intent intent3=new Intent(CommonSDActivity.this, EquipmentSupplyActivity.class);
                    intent3.putExtra("id",supply_cate_id+"");
                    startActivity(intent3);
                }else if(homeType == 7){
                    Prefer.setType(typeid + "");
                    Intent intent3=new Intent(CommonSDActivity.this, ExcipientActivity.class);
                    intent3.putExtra("id",supply_cate_id+"");
                    startActivity(intent3);
                }else if (homeType == 13) {
                    Prefer.setType(typeid + "");
                    Intent intent=new Intent(CommonSDActivity.this, TextileStockActivity.class);
                    intent.putExtra("id",supply_cate_id+"");
                    startActivity(intent);
                } else if (homeType == 10) {
                    Prefer.setType(typeid + "");
                    Intent intent = new Intent(CommonSDActivity.this, TextileEquipmentActivity.class);
                    intent.putExtra("id", supply_cate_id + "");
                    startActivity(intent);
                } else if (homeType == 11) {
                    Prefer.setType(typeid + "");
                    Intent intent = new Intent(CommonSDActivity.this, BackRoadActivity.class);
                    intent.putExtra("id", supply_cate_id + "");
                    startActivity(intent);
                } else if (homeType == 9) {
                    Prefer.setType(typeid + "");
                    Intent intent = new Intent(CommonSDActivity.this, LeaseOfHousesActivity.class);
                    intent.putExtra("id", supply_cate_id + "");
                    startActivity(intent);
                }
                break;
        }
    }

    /**
     * 获取用户信息
     */
    private void getMyNews() {
        Map<String, Object> map = new HashMap<>();
        map.put("token", Prefer.getInstance().getToken());
        XUtil.Post(UrlConfig.MY_NEWS, map, new MyCallBack<String>(){
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    MyNewsModel myNewsModel = new MyNewsModel().toBean(result);
                    if (myNewsModel.getCode() == 1) {
                        type_ps = myNewsModel.getData().getType_ps();
                        type_ep = myNewsModel.getData().getType_ep();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }

    //获取纺织生态圈的数据
    private void getSpinCircleData(String supply_cate_id, String typeid, String keyword) {
        showLoading();
        Map<String, Object> params = new HashMap<>();
        params.put("token", Prefer.getInstance().getToken());
        params.put("supply_cate_id", supply_cate_id);
        params.put("typeid", typeid);
        params.put("keyword", keyword);
        params.put("id", member_id);
        params.put("address_id", Prefer.getInstance().obtainReLocation(this));
        params.put("page", page);
        Log.d("infoaaa",":"+Prefer.getInstance().getToken()+";"+supply_cate_id+";"+typeid+";"+keyword+";"+member_id+";"+Prefer.getInstance().obtainReLocation(this));
        XUtil.Post(UrlConfig.SPIN_CIRCLE, params, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {

                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.optString("code"))) {

                        Gson gson = new Gson();
                        HomeSpinCircleBean circleBean = gson.fromJson(result, HomeSpinCircleBean.class);
                        if (null != circleBean) {
                            if (page == 1) {

                                mRefreshLayout.finishRefresh();
                                mRefreshLayout.resetNoMoreData();
                                if (null != mDataList) {
                                    mDataList.clear();
                                }
                                if (null != mBannerList) {
                                    mBannerList.clear();
                                }
                                mDataList.addAll(circleBean.getData().getData());

                            } else {
                                mRefreshLayout.finishLoadmore();
                                mBaseAdapter.notifyDataSetChanged();
                            }

                            setDataAdapter();
                        }
                    } else if ("100".equals(jsonObject.optString("code"))) {
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    } else {

                        if (page == 1) {
                            MyToast(jsonObject.optString("message"));
                            mRefreshLayout.finishRefresh();
                            mRefreshLayout.resetNoMoreData();
                            if (null != mDataList) {
                                mDataList.clear();
                            }
                            mBaseAdapter.notifyDataSetChanged();
                        } else {
                            MyToast(getResources().getString(R.string.no_more_data));
                            mRefreshLayout.finishLoadmore();
                            mRefreshLayout.finishLoadmoreWithNoMoreData();
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
                hideLoading();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                if (mRefreshLayout != null)
                    mRefreshLayout.finishRefresh();
                ToastUtils.showT("暂无数据");
            }
        });
    }

    //获取banner 集合数据
    private void getBannerData(int typeid) {
        Map<String, Object> params = new HashMap<>();
        params.put("token", Prefer.getInstance().getToken());
        params.put("typeid", typeid);//4-面料供求 5-制造供求 6-原料供求 7-辅料供应 8-人才招聘 29-求职发布
        XUtil.Post(UrlConfig.AD_LIST, params, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.optString("code"))) {
                        Gson gson = new Gson();
                        HomeBannerBean bannerBean = gson.fromJson(result, HomeBannerBean.class);
                        if (null != bannerBean) {
                            if (null != mBannerAllList) {
                                mBannerAllList.clear();
                            }
                            mBannerAllList.addAll(bannerBean.getData());
                            setBannerData();
                        }
                    } else if ("100".equals(jsonObject.optString("code"))) {
                        MyToast(getResources().getString(R.string.login_out));
                        MyApplication.getInstance().gotoLoginActivity();
                    } else {
                        MyToast(jsonObject.optString("message"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }

    //设置数据
    private void setDataAdapter() {
        if (null != mDataList) {
            mBaseAdapter = new BaseRVAdapter(this, mDataList) {
                @Override
                public int getLayoutId(int viewType) {
                    return R.layout.item_find_need_or_supply2;
                }

                @Override
                public void onBind(BaseViewHolder holder, final int position) {
                    final int tagPosition = position;
                    ImageView store_logo_iv = holder.getImageView(R.id.store_logo_iv);//头像
                    TextView store_name_tv = holder.getTextView(R.id.store_name_tv);//名字
                    TextView store_report_content = holder.getTextView(R.id.store_report_content);//发表的标题
                    TextView report_content = holder.getTextView(R.id.report_content);//发表的内容
                    TextView report_time_tv = holder.getTextView(R.id.report_time_tv);//发表的时间
                    TextView look_num_tv = holder.getTextView(R.id.look_num_tv);//浏览的数量
                    TextView comment_num_tv = holder.getTextView(R.id.comment_num_tv);//评论的数量
                    TextView collect_num_tv = holder.getTextView(R.id.collect_num_tv);//收藏的数量
                    TextView get_message_tv = holder.getTextView(R.id.get_message_tv);//获取信息
                    RelativeLayout look_life_more = holder.getRelayout(R.id.look_life_more);//查看更多

                    look_num_tv.setText(mDataList.get(position).getHits() + " 浏览");
                    comment_num_tv.setText(mDataList.get(position).getCommon_nums() + " 评论");
                    collect_num_tv.setText(mDataList.get(position).getCollection_count() + " 收藏");
                    Glide.with(CommonSDActivity.this).load(mDataList.get(position).getMember_thumb()).error(R.drawable.ic_default_photo).into(store_logo_iv);
                    store_name_tv.setText(mDataList.get(position).getMember_no());
                    store_report_content.setText(mDataList.get(position).getTitle());
                    report_content.setText(mDataList.get(position).getContent());
                    report_time_tv.setText(mDataList.get(position).getCreate_time());
                    get_message_tv.setVisibility(View.GONE);

                    look_life_more.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //查看更多 
                            Intent intent = new Intent(CommonSDActivity.this, LookMoreInfoActivity.class);
                            intent.putExtra("member_id", mDataList.get(position).getMember_id());
                            intent.putExtra("one_pid", mDataList.get(position).getOne_pid());
                            intent.putExtra("supply_cate_id", mDataList.get(position).getSupply_cate_id());
                            intent.putExtra("typeid", typeid);
                            startActivity(intent);
                        }
                    });

                    //九宫格展示
                    ArrayList<ImageInfo> imageInfo = new ArrayList<>();
                    List<String> imageDetails = mDataList.get(position).getList_pic();
                    if (imageDetails != null) {
                        for (String imageDetail : imageDetails) {
                            ImageInfo info = new ImageInfo();
                            info.setThumbnailUrl(imageDetail);
                            info.setBigImageUrl(imageDetail);
                            imageInfo.add(info);
                        }
                    }

                    NineGridView mRecyclerView = holder.getView(R.id.mRecyclerView);//图片的列表 3 列
                    mRecyclerView.setSingleImageSize(500);
                    mRecyclerView.setAdapter(new NineGridViewClickAdapter(mContext, imageInfo));
                    
//                    RecyclerView mRecyclerView = holder.getView(R.id.mRecyclerView);//图片的列表 3 列
//                    mRecyclerView.setLayoutManager(new GridLayoutManager(CommonSDActivity.this, 3, GridLayoutManager.VERTICAL, false));
//                    BaseRVAdapter mPicAdapter = new BaseRVAdapter(CommonSDActivity.this, mDataList.get(position).getList_pic()) {
//                        @Override
//                        public int getLayoutId(int viewType) {
//                            return R.layout.item_find_pic;
//                        }
//
//                        @Override
//                        public void onBind(BaseViewHolder holder, final int position) {
//                            ImageView find_pic_iv = holder.getImageView(R.id.find_pic_iv);
//                            Glide.with(CommonSDActivity.this).load(mDataList.get(tagPosition).getList_pic().get(position)).into(find_pic_iv);
//                            find_pic_iv.setOnClickListener(new View.OnClickListener() {
//                                @Override
//                                public void onClick(View v) {
//                                    if (0 != mDataList.size()) {
//                                        //点击查看大图
//                                        Intent intent = new Intent(CommonSDActivity.this, LookBigPicActivity.class);
//                                        intent.putExtra("imgUrl", mDataList.get(tagPosition).getList_pic_compress().get(position));
//                                        intent.putExtra("listData", mDataList.get(tagPosition));
//                                        intent.putExtra("type", "1");
//                                        startActivity(intent);
//                                    }
//                                }
//                            });
//                        }
//
//                    };
//                    mRecyclerView.setAdapter(mPicAdapter);
//                    mPicAdapter.notifyDataSetChanged();
                }
            };
        }
        carListRecycler.setAdapter(mBaseAdapter);
        mBaseAdapter.addItemClickListener(new BaseRVAdapter.OnItemClickListener() {
            @Override
            public void itemSelect(int position) {
//                if (homeType == 4) {
                    //TalkDetailActivity2
                    String address_id = Prefer.getInstance().obtainReLocation(CommonSDActivity.this);
                    if (address_id.length() == 0) {
                        ToastUtils.showT("未选择地区");
                        return;
                    }
                    String id = mDataList.get(position).getId() + "";
//                    System.out.println("--------->id=" + id + "\n----->supply_cate_id=" + supply_cate_id + "\n---------->address_id=" + address_id);
                    Intent intent = new Intent(CommonSDActivity.this, FindDetailActivity2.class);
                    intent.putExtra("typeid", Integer.valueOf(supply_cate_id));
                    intent.putExtra("address_id", address_id);
                    intent.putExtra("id", Integer.valueOf(id));
                    startActivity(intent);

//                }
            }
        });
    }

    //设置banner 数据
    private void setBannerData() {
        if (null != mBannerAllList) {
            for (int i = 0; i < mBannerAllList.size(); i++) {
                mBannerList.add(i, mBannerAllList.get(i).getImg_face());
            }
            commentBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);//设置圆形指示器与标题
            commentBanner.setIndicatorGravity(BannerConfig.CENTER);//设置指示器位置
            commentBanner.setImages(mBannerList);
            commentBanner.setImageLoader(new GlideImageLoader());
            commentBanner.start();

            commentBanner.setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {
                    //用mBannerAllList集合
                }
            });
        }
    }

    @Override
    public void onLoadmore(RefreshLayout refreshlayout) {
        refreshlayout.getLayout().postDelayed(new Runnable() {
            @Override
            public void run() {
                page++;
                getSpinCircleData(supply_cate_id, typeid + "", "");
            }
        }, 2000);
    }

    @Override
    public void onRefresh(final RefreshLayout refreshlayout) {
        refreshlayout.getLayout().postDelayed(new Runnable() {
            @Override
            public void run() {
                page = 1;
                getSpinCircleData(supply_cate_id, typeid + "", "");
            }
        }, 2000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
